# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 利用元类来实现单例模式.py
Author: kij
Create Date: 2021/2/18
-------------------------------------------------
"""
# 利用元类来实现单例模式
class Klass(type):
	def __init__(self,class_name,class_bases,class_dic):
		print("")
		super(Klass, self).__init__(class_name,class_bases,class_dic)
		self.__instance = None

	def __call__(self, *args, **kwargs):
		if not self.__instance:
			obj = object.__new__(self)
			self.__init__(obj)
			self.__instance = obj
		return self.__instance

class Mysql(object,metaclass=Klass):
	def __init__(self):
		print("大哥天下第一")

mysql = Mysql()
mysql1 = Mysql()
mysql2 = Mysql()
print(id(mysql))
print(id(mysql1))
print(id(mysql2))